<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        class ProxySandbox {
            constructor() {
                const rawWindow = window;
                const fakeWindow = {}
                const proxy = new Proxy(fakeWindow, {
                    set(target, p, value) {
                        target[p] = value;
                        return true
                    },
                    get(target, p) {
                        return target[p] || rawWindow[p];
                    }
                });
                this.proxy = proxy
            }
        }
        let sandbox1 = new ProxySandbox();
        let sandbox2 = new ProxySandbox();
        window.a = 1; // rawWindow.a = 1
        ((window) => {
            window.a = 'hello'; //fakeWindow.a = 'hello'
            console.log(window.a) // console.log(fakeWindow.a || rawWindow.a) ==>hello
        })(sandbox1.proxy);
        ((window) => {
            window.a = 'world'; //fakeWindow.a = 'world'
            console.log(window.a) // console.log(fakeWindow.a || rawWindow.a) ==> world
        })(sandbox2.proxy);
        console.log(window.a) // 1
    </script>
</body>
</html>